﻿using System;
using System.Web.Mvc;
using SimpleScrum.Areas.Scrum.Models;
using SimpleScrum.Core.Entities;
using SimpleScrum.Utils;

namespace SimpleScrum.Areas.Scrum.Controllers
{
    public class UserStoryTaskController : Controller
    {
        public UserStoryTaskModel ObjTask;
        public UserStoryModel ObjUserStory;
        public UsersModel ObjUsers;

        public UserStoryTaskController()
        {
            ObjUserStory = new UserStoryModel();
            ObjUsers = new UsersModel();
            ObjTask = new UserStoryTaskModel();
        }

        //
        // GET: /Task
        [HttpGet]
        public ActionResult New(Guid userStoryId)
        {
            var task = new UserStoryTask
                {
                    AssignTo = ObjUsers.GetUsersById(@Client.Instance.ClientId)
                };
            return View(task);
        }

        //
        // POST: /Task
        [HttpPost]
        public ActionResult New(Guid userStoryId, UserStoryTask userStoryTask)
        {
            try
            {
                userStoryTask.UserStory = ObjUserStory.GetUserStoryById(userStoryId);
                userStoryTask.AssignDate = DateTime.Now;
                userStoryTask.AssignTo = ObjUsers.GetUsersById(@Client.Instance.ClientId);
                ObjTask.NewTask(userStoryTask);
                return RedirectToAction("Details", "UserStory", new {id = userStoryId});
            }
            catch (Exception)
            {
                return View();
            }
        }

        //
        // GET: /Task
        //
        // POST: /Task
        //
        // GET: /Task
        //
        // POST: /Task
        //
        // GET: /Task
        //
        // POST: /Task
    }
}